package cn.javadog.algorithm.m1_100;


/**
 * 盛最多水的容器
 * https://leetcode-cn.com/problems/container-with-most-water/
 * @author Sprite
 */
public class Algorithm11 {
	public static void main(String[] args) {
		int[] h = new int[]{1,8,6,2,5,4,8,3,7};
		System.out.println(maxArea(h));
	}

	public static int maxArea(int[] height) {
		// 两头往中间推
		int left = 0;
		int right = height.length-1;
		int area = 0;
		while (left<right){
			area = Math.max(area, (right-left)*Math.min(height[left],height[right]));
			if (height[left] > height[right]){
				right--;
			}else {
				left++;
			}
		}
		return area;
	}
}
